package com.sc.nft.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.dto.OrderDTO;
import com.sc.nft.entity.Order;
import com.sc.nft.entity.dto.OrderDetailsDTO;
import com.sc.nft.entity.dto.RefundOrderPageDTO;
import com.sc.nft.entity.vo.OrderDetailListVO;
import com.sc.nft.entity.vo.OrderSimpleVO;
import com.sc.nft.entity.vo.RefundOrderPageVO;
import com.sc.nft.enums.OrderStatusEnum;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 订单表(sc_order)数据Mapper
 *
 * @author zxy
 * @description 由 Mybatisplus Code Generator 创建
 * @since 2022-06-02 01:04:25
 */
@Mapper
public interface OrderMapper extends BaseMapper<Order> {

    OrderDetailsDTO getOrderDetailsById(@Param("id") Long id);

    /**
     * 查询一周某商品的销售额
     *
     * @return
     */

    List<OrderSimpleVO> orderExport(@Param("productId") Long productId);

    List<OrderDetailListVO> orderDetailExport(@Param("productId") Long productId, @Param("payTimeFrom") Date payTimeFrom, @Param("payTimeTo") Date payTimeTo);





    /**
     * @param start   起始条目
     * @param end     结束条目
     * @param orderId 查询区间订单号
     * @return
     */
    Integer findLimitBetween(@Param("start") Long start, @Param("end") Long end, @Param("orderId") Long orderId,@Param("collectionId")Integer collectionId);

    /**
     * 获取总数
     * @param collectionId
     * @return
     */
    Integer findLimitBetweenSum(@Param("collectionId")Integer collectionId);


    Integer getSumCountByProductId(@Param("productIds") List<Long> productId);

    /**
     * 昨日一级售出总额
     * @return
     */
    BigDecimal getToDaySellAmount();

    /**
     * 获取一级市场全部销售总额
     * @return
     */
    BigDecimal getAllSumSellAmount();

    /**
     * 获取昨日售出数量
     * @return
     */
    Integer getToDaySellCount();

    Integer getToDaySellCountByDay(@Param("day") String day);
    /**
     * 昨日购买用户总数量
     * @return
     */
    Integer getToDaySellBuyUserCount();

    Integer getToDaySellBuyUserCountByDay(@Param("day") String day);

    BigDecimal getToDaySellAmountByDay(@Param("day") String day);

    BigDecimal getAllSumSellAmountByDay(@Param("day") String day);

    Integer getYesterDayCountByCollectionId(@Param("collectionId") Long collectionId);

    Integer getYesterDayCountByCollectionIdByDay(@Param("collectionId") Long collectionId, @Param("day") String day);

    Integer getCountByProductId(@Param("productId") Long productId);





    /**
     * 订单分页
     *
     * @param userId
     * @param orderNo
     * @param productId
     * @param status
     * @param startOrderTime
     * @param endOrderTime
     * @param startPayTime
     * @param endPayTime
     * @param page
     * @return
     */
    Page<OrderDTO> orderDTOPageForAdmin(Page page,
                                        @Param("firstTitle") String firstTitle,
                                        @Param("userId") Long userId,
                                        @Param("orderNo") String orderNo,
                                        @Param("productId") Long productId,
                                        @Param("status") OrderStatusEnum status,
                                        @Param("startOrderTime") Date startOrderTime,
                                        @Param("endOrderTime") Date endOrderTime,
                                        @Param("startPayTime") Date startPayTime,
                                        @Param("endPayTime") Date endPayTime);

    @Select("select * from sc_order where is_delete=0 and status=2 and pay_time>'2023-12-18 00:00:00' and is_team_income=1 order by id ")
    List<Order> initTmp();
    @Select("select * from sc_order where is_delete=0 and status=2 and pay_time>'2023-11-23 00:00:00' and is_team_income=1 order by id ")
    List<Order> initTmp2();
    /**
     * 获取退款数据
     * @param mp
     * @param request
     * @return
     */
    IPage<RefundOrderPageVO> refundOrderPage(Page mp, @Param("request") RefundOrderPageDTO request,Long userId);
}
